<?php

/*
	Class: MailMessages

	About: Author
		Jaybill McCarthy

	About: License
		<http://communit.as/docs/license>

	About: See Also
		<Mail_Db_Table>
*/
class MailMessages extends Mail_Db_Table {

	/* Group: Instance Variables */

	/*
		Variable: $_name
			The name of the table or view to interact with in the data source.
	*/
    protected $_name = 'mail_messages';

	/*
		Variable: $_primary
			The primary key of the table or view to interact with in the data source.
	*/
    protected $_primary = 'id';

	/* Group: Instance Methods */

	/*
		Function: getNewMailByUsername
			Counts the number of unread messages a user has.

		Arguments:
			username - The username of the user for which to count messages.

		Returns: int
	*/
	public function getNewMailByUsername($username) {
		$where = $this->getAdapter()->quoteInto('to_username = ? and folder = "INBOX" and status="NEW"', $username);
		return ($this->getCountByWhereClause($where));
	}

	/*
		Function: getSentMailByUsername
			Counts the number of messages a user has sent.

		Arguments:
			username - The username of the user for which to count messages.

		Returns: int
	*/
	public function getSentMailByUsername($username) {
		$where = $this->getAdapter()->quoteInto('from_username = ? and folder = "SENT" and status="SENT"', $username);
		return ($this->getCountByWhereClause($where));
	}

	/*
		Function: getAllMailByUsername
			Counts the number of messages a user has sent and recieved.

		Arguments:
			username - The username of the user for which to count messages.

		Returns: int
	*/
	public function getAllMailByUsername($username) {
		$where = $this->getAdapter()->quoteInto('to_username = ? and folder = "INBOX"', $username);
		return ($this->getCountByWhereClause($where));
	}
    
}
